home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2959 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.9 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Locaton of an array?
  5. Date: 24 Jan 1996 08:16:48 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4e5m1gINNeh5@keats.ugrad.cs.ubc.ca>
  8. References: <4d4iqk$hs3@overload.lbl.gov> <4d698s$g4r@news.iag.net> <4d6nd7$4gg@overload.lbl.gov>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4d6nd7$4gg@overload.lbl.gov>,
  12. Mikhail Faiguenblat  <mfaiguen@issserv4.lbl.gov> wrote:
  13. >Tanmoy Bhattacharya (tanmoy@qcd.lanl.gov) wrote:
  14. >[stuff deleted]
  15. >:    Btw, just  out of curiosity, why do you care where it lives in  
  16. >:    absolute RAM?
  17. >
  18. >I just posted the description of the problem.
  19. >Also, if anyone has written or knows of a C program that uses DMA, how did
  20. >you deal with the issue of having to specify the physical addresses (I do not
  21. >know if that is the issue for other processors, but for x86 it is).
  22. >
  23. >: By the way, the output of %p (as also the result of the (int) cast on
  24. >: a pointer) is upto the implementation. C can be implemented on machines
  25. >: which have no natural mapping onto a flat address space, so the
  26. >: original question may not have a definite meaning. An answer to the
  27. >: `why' that you ask is definitely required before more help can be
  28. >: provided.
  29. >Ok, so C works with virtual addresses, and all the registers (such as
  30. >segment register, offset register, etc.) also store virtual addresses.
  31. >Also, a program when being executed writes to and reads from real memory.
  32. >This means that somewhere there is a virtual memory mamnager (?) which 
  33. >keeps track of which segment of virtual memory corresponds to which
  34. >segment of real memory.
  35. >Is it done on kernel level?
  36.  
  37. Yes and no. The kernel keeps track of free pages, and adds/removes them to the
  38. page directories of processes as needed.
  39.  
  40. However, the translation from virtual to physical addresses is done by the CPU
  41. hardware. The CPU knows the physical address of the page directory---it has a
  42. special register that tells it where to find it. As an important optimization,
  43. the CPU stores recently looked-up translations in a special buffer called the
  44. translation lookaside buffer (or virtual address translation cache, if you
  45. don't like IBM terminology) so it doesn't have to walk the page directory for
  46. every memory reference. Without the buffer, the system would run like an utter
  47. dog.
  48.  
  49. So, the CPU implements the address translation and the means to catch accesses
  50. to protected or not-present pages with special exceptions. The kernel manages
  51. the allocation of pages to page directories, the swapping of pages to and from
  52. disk, and so forth.
  53.  
  54. If you want to access some hardware locations directly from a user processe,
  55. you have to request a mapping from the OS, which will "nail" the device's
  56. memory aperture to some range of virtual addresses that will then be accessible
  57. to your process.
  58. -- 
  59.  
  60.